package com.sline.DynamicProxy;

import java.lang.reflect.Proxy;

public class Test {
    public static void main(String[] args) {
        UserImp userImp = new UserImp();
        userImp.add();
        userImp.delete();

        System.out.println("----------------------");

        MyInvacationHandler mih = new MyInvacationHandler(userImp);
        User u = (User) Proxy.newProxyInstance(userImp.getClass().getClassLoader(), userImp.getClass().getInterfaces(), mih);
        u.add();
        u.delete();

        System.out.println("=======================");

        Student student = new Student();
        student.study();
        student.goToSchool();

        MyInvacationHandler mih1 = new MyInvacationHandler(student);
        BaseStudent baseStudent = (BaseStudent) Proxy.newProxyInstance(student.getClass().getClassLoader(), student.getClass().getInterfaces(), mih1);
        baseStudent.study();
        baseStudent.goToSchool();
    }
}
